﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/*
    모든 WorkInfo 얻는 방법.
    WorkManager wm = WorkManager.Instance();
    foreach (WorkInfo wi in wm.workinfoList)
    {
        wi.startTime.Ticks;
    }
 */

namespace schedule
{
    class WorkManager
    {
        private static WorkManager _instance;
        public List<WorkInfo> workinfoList = new List<WorkInfo>();
        public bool ableAlarm = false;

        public string[] categoryNames =
        {
            "영어",
            "수학",
            "프로그래밍",
            "공부",
            "축구",
            "농구",
            "야구",
            "등산",
            "리그오브레전드",
            "스타크래프트",
            "심시티",
            "디아블로3",
            "영화",
            "식사",
            "쇼핑",
            "공연",
        };




        // get Instance
        public static WorkManager Instance()
        {
            if (_instance == null)
            {
                _instance = new WorkManager();
            }
            return _instance;
        }

        public WorkManager()
        {
            WorkManager wm = this;
            WorkInfo wi;

            // 사용자
            wi = new WorkInfo();
            wi.title = "프로그래밍 공부";
            wi.category = categoryNames[2];
            wi.owner = "사용자";
            wi.startTime = new DateTime(2013, 6, 19);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.title = "HCI 작업";
            wi.category = categoryNames[3];
            wi.owner = "사용자";
            wi.startTime = new DateTime(2013, 6, 3);
            wi.endTime = new DateTime(2013, 6, 7);
            wm.add(wi);

            wi = new WorkInfo();
            wi.title = "시험 시작";
            wi.category = categoryNames[3];
            wi.owner = "사용자";
            wi.startTime = new DateTime(2013, 6, 10);
            wi.endTime = wi.startTime;
            wm.add(wi);



            // dummy
            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "축구 모임!!";
            wi.category = categoryNames[4];
            wi.owner = "강정욱";
            wi.startTime = new DateTime(2013, 6, 17);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "LOL 한판";
            wi.category = categoryNames[8];
            wi.owner = "최형민";
            wi.startTime = new DateTime(2013, 6, 15);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "원어민 강사랑 공부";
            wi.category = categoryNames[0];
            wi.owner = "원세종";
            wi.startTime = new DateTime(2013, 6, 12);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "영어 회화 합시다.";
            wi.category = categoryNames[0];
            wi.owner = "김철수";
            wi.startTime = new DateTime(2013, 7, 2);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "미적분이란 도대체?";
            wi.category = categoryNames[1];
            wi.owner = "김비마";
            wi.startTime = new DateTime(2013, 6, 20);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "포인트에 대해 공부";
            wi.category = categoryNames[2];
            wi.owner = "박참빛";
            wi.startTime = new DateTime(2013, 6, 21);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "자기 계발 공부";
            wi.category = categoryNames[3];
            wi.owner = "정한울";
            wi.startTime = new DateTime(2013, 7, 10);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "싸커";
            wi.category = categoryNames[4];
            wi.owner = "정옥의";
            wi.startTime = new DateTime(2013, 7, 5);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "슬램덩크 하실분";
            wi.category = categoryNames[5];
            wi.owner = "최화도";
            wi.startTime = new DateTime(2013, 8, 10);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "요시! 그란도시즌!";
            wi.category = categoryNames[6];
            wi.owner = "서누리";
            wi.startTime = new DateTime(2013, 7, 11);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "산타고 경치 구경";
            wi.category = categoryNames[7];
            wi.owner = "김태희";
            wi.startTime = new DateTime(2013, 6, 8);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "레이팅 올려봅시다.";
            wi.category = categoryNames[8];
            wi.owner = "이삼성";
            wi.startTime = new DateTime(2013, 6, 22);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "스타 3:3 하실분";
            wi.category = categoryNames[9];
            wi.owner = "박중도";
            wi.startTime = new DateTime(2013, 7, 1);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "심시티 노원구 만들기";
            wi.category = categoryNames[10];
            wi.owner = "김목동";
            wi.startTime = new DateTime(2013, 7, 29);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "악마를 잡으러 떠나자";
            wi.category = categoryNames[11];
            wi.owner = "이보성";
            wi.startTime = new DateTime(2013, 7, 8);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "아이언맨3 같이 보실분";
            wi.category = categoryNames[12];
            wi.owner = "전두완";
            wi.startTime = new DateTime(2013, 6, 9);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "맛집 찾기 여행";
            wi.category = categoryNames[13];
            wi.owner = "이멍박";
            wi.startTime = new DateTime(2013, 6, 23);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "같이 하는 쇼핑";
            wi.category = categoryNames[14];
            wi.owner = "박정이";
            wi.startTime = new DateTime(2013, 6, 26);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "공연 봅시다";
            wi.category = categoryNames[15];
            wi.owner = "이숭만";
            wi.startTime = new DateTime(2013, 7, 2);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "잉글리시 타임";
            wi.category = categoryNames[0];
            wi.owner = "노무헌";
            wi.startTime = new DateTime(2013, 7, 5);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "1+1 은 귀요미가 아님. 2임";
            wi.category = categoryNames[1];
            wi.owner = "노진구";
            wi.startTime = new DateTime(2013, 7, 22);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "안드로이드 공부 하실분";
            wi.category = categoryNames[2];
            wi.owner = "윤보서";
            wi.startTime = new DateTime(2013, 7, 27);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "시험 공부를 위한 모임";
            wi.category = categoryNames[3];
            wi.owner = "김과진";
            wi.startTime = new DateTime(2013, 7, 10);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "조기축구 모임";
            wi.category = categoryNames[4];
            wi.owner = "김대준";
            wi.startTime = new DateTime(2013, 6, 28);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "맨투맨 하실분~~";
            wi.category = categoryNames[5];
            wi.owner = "김영섬";
            wi.startTime = new DateTime(2013, 6, 10);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "야구 관람 갑시다";
            wi.category = categoryNames[6];
            wi.owner = "노대우";
            wi.startTime = new DateTime(2013, 6, 21);
            wi.endTime = wi.startTime;
            wm.add(wi);

            wi = new WorkInfo();
            wi.isPublic = true;
            wi.title = "5:5 대전 합시다";
            wi.category = categoryNames[8];
            wi.owner = "박종우";
            wi.startTime = new DateTime(2013, 6, 11);
            wi.endTime = wi.startTime;
            wm.add(wi);

        }

        // 할일 추가
        public void add(WorkInfo wi)
        {
            workinfoList.Add(wi);
        }

        // MakeForm 에 있는 값들로 WorkInfo 에 값을 채워준다.
        public void changeWorkInfo(WorkInfo wi, MakeForm makeForm)
        {
            // 이 함수를 실행 하는 자는 실제 사용자.
            if (wi.owner == null || wi.owner.Length == 0)
                wi.owner = "사용자";

            wi.startTime = new DateTime(makeForm.dtpStart.Value.Year, makeForm.dtpStart.Value.Month, makeForm.dtpStart.Value.Day);
            wi.endTime = new DateTime(makeForm.dtpEnd.Value.Year, makeForm.dtpEnd.Value.Month, makeForm.dtpEnd.Value.Day);
            wi.title = makeForm.tbTitle.Text;
            wi.place = makeForm.tbPlace.Text;
            wi.summary = makeForm.tbSummary.Text;

            if (makeForm.checkBox1.Checked)
                wi.isPublic = true;
            else
                wi.isPublic = false;
            // TODO :
            // " > 스포츠 > 축구" 
            // 이놈을 
            // "축구" 로 바꾸어야 함.
            wi.category = makeForm.button1.Text;
            if (makeForm.textBox6.Text.Length > 0)
                wi.maxMember = Convert.ToInt32(makeForm.textBox6.Text);
            wi.password = makeForm.textBox5.Text;

            for (int i = 0; i < makeForm.getInvateListSize(); i++)
            {
                string friend = makeForm.getInvateFriend(i);
                wi.acceptList.Add(friend);
            }
        }

        // WorkInfo 에 있는 값들로 MakeForm을 채워준다.
        public void changeMakeForm(WorkInfo wi, MakeForm makeForm)
        {
            makeForm.tbOwner.Text = wi.owner;
            makeForm.tbTitle.Text = wi.title;
            makeForm.dtpStart.Value = wi.startTime;
            makeForm.dtpEnd.Value = wi.endTime;
            makeForm.tbPlace.Text = wi.place;
            makeForm.tbSummary.Text = wi.summary;
            if (wi.isPublic)
            {
                makeForm.checkBox1.Checked = true;
                makeForm.checkBox2.Checked = false;
            }
            else
            {
                makeForm.checkBox1.Checked = false;
                makeForm.checkBox2.Checked = true;
            }
            makeForm.button1.Text = wi.category;
            makeForm.textBox6.Text = Convert.ToString(wi.maxMember);
            makeForm.textBox5.Text = wi.password;

            foreach (string accept in wi.acceptList)
            {
                makeForm.addInvateList(accept);
            }
        }

        // 내가 만든 일인지
        public bool isMadeByMe(WorkInfo wi)
        {
            return wi.owner == "사용자";
        }

        // 내가 참여한 일인지
        public bool isMyGroup(WorkInfo wi)
        {
            if (wi.owner == "사용자")
                return true;
            if (wi.isJoin)
                return true;

            return false;
        }
    }

    public class WorkInfo
    {
        // 일감 소유자. (더미는 타 이름으로)
        public string owner;

        public DateTime startTime;
        public DateTime endTime;
        public string title;
        public string place;
        public string summary;
        public bool isPublic;
        public string category;
        public int maxMember;
        public string password;
        public List<string> acceptList = new List<string>(); // 참여 인원

        // 사용자가 일감에 참여를 했는가?
        public bool isJoin;

        public WorkInfo()
        {
            isPublic = true;
            isJoin = false;
        }
    }
}
